package com.java2401.yangnan.service.impl;

import com.java2401.yangnan.mapper.UserMapper;
import com.java2401.yangnan.pojo.User;
import com.java2401.yangnan.service.UserService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.sql.Date;
import java.util.List;

@Service
@Transactional
public class UserServiceImpl implements UserService {
    @Resource
    UserMapper userMapper;
    @Override
    public User selectByPrimaryKey(Integer id) {
        return userMapper.selectByPrimaryKey(id);
    }

    @Override
    public User selectByCard(String card) {
        return userMapper.selectByCard(card);
    }

    @Override
    public List<User> allUserPage() {
        List<User> users = userMapper.allUserPage();
        return users;
    }

    @Override
    public Integer insert(User user) {
        return userMapper.insert(user);
    }

    @Override
    public int saveDateCheck(User user) {
        if (!checkEventsituation((user.getName()))) {
            return -1;
        }
        return userMapper.insert(user);
    }
    private boolean checkEventsituation(String eventSituation){
        User p = new User();
        p.setName(eventSituation);
        List<User> collegeList=userMapper.selectDName(eventSituation);
        if(collegeList.size()>0){
            return false;
        }
        return true;
    }

    @Override
    public Integer update(User user) {
        return userMapper.update(user);
    }

    @Override
    public List<User> selectAllByDel(List<Integer> ids) {
        return userMapper.selectAllByDel(ids);
    }

    @Override
    public int deleteAll(List<Integer> ids) {
        return userMapper.deleteAll(ids);
    }

    @Override
    public int deleteByPrimaryKey(Integer id) {

        return userMapper.deleteByPrimaryKey(id);
    }

    @Override
    public List<User> selectByDname(String name, Integer age,Date startTime, Date endTime) {
        return userMapper.selectByDname(name,age, startTime, endTime);
    }

}
